package cn.jdy.plugins.wap;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import cn.jdy.common.ctrl.BaseCtrl;
import cn.jdy.framework.util.DateUtil;
import cn.jdy.framework.util.IpUtil;
import cn.jdy.plugins.entity.LeaveMsg;
import cn.jdy.plugins.service.LeaveMsgService;

/**
 * 地图控制类
 *
 * @author Tianyi
 * @date 2014-08-26
 */
@RestController
@RequestMapping("/message")
public class MessageCtrl extends BaseCtrl {

	@Autowired
	private LeaveMsgService leaveMsgService;
	/**
	 * 首页
	 */
	@RequestMapping("")
	public ModelAndView init(String status) {
		ModelAndView mv = new ModelAndView(super.t + "/message");
		if("1".equals(status)) mv.addObject("msg", "提交成功");
		return mv;
	}
	/**
	 * 保存留言
	 */
	@RequestMapping("/save")
	public ModelAndView save(LeaveMsg entity) {
		ModelAndView mv = new ModelAndView("redirect:/message");
		entity.setCreateTime(DateUtil.getCurrentDate(DateUtil._DEFAULT2));
		entity.setIp(IpUtil.getIp(request));
		leaveMsgService.save(entity);
		mv.addObject("status", "1");
		return mv;
	}
}
